<template>
	<view class="quan">
		<!-- 头部 -->
		
		<view class="top">
			
			<image src="/static/beijing.png" class="top_bj_img" />
			
			<view class="top_nav">
					<image class="saoyisao" src="../../static/saoyisao.png" @tap="classify"></image>
				<view class="top_left" @click="hui"></view>
				 <view class="top_right" @click="register">注册</view>
			</view>
		</view> 
		<!-- 申请登录浮动框 -->   
		<view class="float">  
			<view class="float_tatal">
				<form @submit="formSubmit" @reset="formReset">
					<view class="login_tel">
						<image src="/static/tel.png" class="img"><input type="number" maxlength="11" name="tel" placeholder="请输入手机号码"   />
					</view>
    
					<view class="login_pass">
						<image src="/static/mm.png" class="img"><input class="login_password" type="text" name="password" :password="see"
							 placeholder="请输入您的密码" />
							<view class="loginsee_btn" @tap="login_look">
								<image class="yan" :src="yan" />
							</view>
					</view>
					<view class="forget_pass" @tap="forget_pass">忘记密码</view>
					<view class="btn"><button type="primary" form-type="submit">登录</button></view>
					
				</form>
			</view>

		</view>
	</view>
	</view>
</template>

<script>
	import {mapMutations} from 'vuex';
	import store from '../../store'
	export default {
		data() {
			return {
				login: 1,
				see: true,
				tel: '',
				yhxx: '',
				yan:'/static/yan2.png',
				idmd5:'',
				tyid:'',
			}
		},
		onLoad(option) {
			this.tyid=option.tyid
			let _this = this;
			uni.onNetworkStatusChange(function (res) {
			    console.log("网络状态",res.isConnected);
			    console.log("网罗状态2",res.networkType);
			});
			//#ifdef MP-WEIXIN
			// 小程序登录
			// 获取用户信息
			// uni.getUserInfo({
			// 	provider: 'weixin',
			// 	success: function(infoRes) {
			// 		console.log('-------获取微信用户所有-----');
			// 		console.log(JSON.stringify(infoRes.userInfo));
			// 	}
			// });
			// 	uni.login({
			// 			provider: 'weixin',
			// 			success: function(loginRes) {
			// 				console.log('-------获取openid(unionid)-----',loginRes.code);
			// 				console.log(JSON.stringify(loginRes));
			// 				// 获取用户信息
			// 				    uni.getUserInfo({
			// 				      provider: 'weixin',
			// 				      success: function (infoRes) {
			// 				        console.log('用户昵称为：' + infoRes.userInfo.nickName);
			// 				      }
			// 				    });
			// 				uni.request({
			// 					url:'http://tuiguang.yiyunoto.com/api/login/xcxlogin',
			// 					// header:{authtoken:res.data},
			// 					data:{
			// 						code:loginRes.code
			// 					},
			// 					method:'POST',  
			// 					success:(res)=>{ 
			// 						console.log("小程序",res)
			// 						// this.$store.state.token=res.data.data.accesstoken;
			// 						_this.$store.commit('UserInfo',res.data.data.accesstoken)
			// 						if(res.data.code==1){
			// 							uni.navigateTo({
			// 								url:'../Binding_phone/Binding_phone?id='+res.data.data.accesstoken
			// 							})
			// 						}
			// 					},
			// 					fail:(res)=>{
			// 						console.log("请求失败",res)
			// 					}
			// 				})
							
			// 			}   
			// 		});
			//小程序登录结束
			//#endif
			
			if(this.tyid !="1"){
			uni.getStorage({
			    key:"login",
			    success: function (res) {
					_this.idmd5=res.data
			        console.log(_this.idmd5);
					console.log("我也不知道这是啥，就是想试试",res.data);
					_this.$store.commit('UserInfo',res.data)
					
					uni.request({
						url:'http://tuiguang.yiyunoto.com/api/index/index',
						header:{authtoken:res.data},
						method:'POST',  
						success:(res)=>{  
							if(res.data.msg=="该账号在其他设备登录"){
								uni.showToast({
									title:"该账号在其他设备登录，请从新登陆",
									icon:'none'
								})
								return;
							}else{
								console.log('12')
								uni.switchTab({
									url:'../index/index'
								})
							}			
						},
						fail:(res)=>{
							console.log("请求失败",res)
						}
					})
					
			    }
			});
			}
		},
		methods: {
			...mapMutations(['logins']),
			hui: function() {
				console.log("点击")
				uni.navigateTo({
					url: "../index/index"
				})
			},
			classify:function(e){
				console.log("扫码",e)
				uni.scanCode({
				 success:(res)=> {
				  console.log("扫码成功121",res.result)
				  console.log("扫码成功2",res)
				 uni.request({
				 	url:res.result,
				 	method:'GET',  
				 	success:(res)=>{  
				 		console.log("邀请人信息请求成功",res)
						uni.navigateTo({
							url:'../register/register?yqr='+res.data.data
						})
				 	},
				 	fail:(res)=>{
				 		console.log("请求失败",res)
				 	}
				 })
				 }
				})
		
		},
			register: function() {
				uni.navigateTo({
					url: "../register/register"
				})
			},
			login_look: function() {
				this.see = !this.see
				if(this.see==false){
				this.yan='/static/yan.png'
				}else{
					this.yan='/static/yan2.png'
				}
			},
			forget_pass: function() {
				uni.navigateTo({
					url: "../forget_password/forget_password"
				})
			},
			formSubmit: function(e) {
				console.log(e.detail.value)
				this.yhxx = e.detail.value
				var content = this.yhxx
				uni.onNetworkStatusChange(function (res) {
				    console.log("网络状态",res.isConnected);
				    console.log("网罗状态2",res.networkType);
				});
				uni.request({
					url: 'http://tuiguang.yiyunoto.com/api/login/login',
					method: 'POST',
					headers:{'Content-Type':'application/json'},
					data: {
						phone: content.tel,
						pwd: content.password
					},
					success: (res) => {
						console.log("登录成功", res)
						this.$api.msg(res.data.msg);
						if (res.data.msg == "登陆成功") {
							this.$store.state.token=res.data.data;
							try{
								console.log("本地数据缓存成功")
								uni.setStorageSync('login',res.data.data)
								
							}catch(e){
								//TODO handle the exception
							}
							
							console.log(res);
							// this.login(result.data);
							uni.switchTab({  
							  url: '../index/index'  
							});
							console.log("条了")
						}
						console.log(res.data.data);
					},
					fail: (res) => {
						console.log("登录失败", res)
						this.$api.msg(res.data.msg);
					}
				});
			},
			
		}
	}
</script>

<style>
	.top {
		width: 100%;
		height: 400upx;
	}

	.top_bj_img {
		width: 100%;
		height: 100%;
	}
	.saoyisao{
		width:50upx ;
		height:50upx ;
		
		
	}

	.top_nav {
		width: 100%;
		height: 100upx;
		position: absolute;
		top: 20upx;
		padding-top: 50upx;
		padding-left: 20upx;
		box-sizing: border-box;
	}

	.top_left {
		padding:20upx;
		float: left;
		box-sizing: border-box;
	}

	.top_right {
		float: right;
		width: 100upx;
		margin-right: 20upx;
		color: #FFFFFF;
	}

	.float {
		width: 90%;
		box-shadow: 0upx 10upx 10upx #0C0800;
		border-radius: 10upx;
		margin-left: 5%;
		padding-bottom: 50upx;
		position: relative;
		top: -200upx;
		background: #FFFFFF;
	}

	/* 登录项浮动框 */
	.login_top {
		width: 90%;
		height: 180upx;
		margin: 0 auto;
	}

	.img {
		width: 50upx;
		height: 50upx;
		border-radius: 25upx;
		position: absolute;
		left: 70upx;
		float: left;
	}

	.login_tel {
		width: 80%;
		height: 100upx;
		padding: 100upx;
		margin-left: 10%;
		box-sizing: border-box;
		border-bottom: 2upx solid #DBDADA;
	}

	.login_pass {
		width: 80%;
		height: 100upx;
		padding: 100upx;
		margin-left: 10%;
		box-sizing: border-box;
		border-bottom: 2upx solid #DBDADA;
	}

	.login_password {
		width: 80%;
		float: left;
	}

	.yan {
		width: 60upx;
		height: 40upx;
	}

	.loginsee_btn {
		width: 20%;
		font-size: 26upx;
		text-align: right;
		float: right;
	}

	.forget_pass {
		padding: 50upx;
		box-sizing: border-box;
		color: blue;
		font-size: 26upx;
	}

	.btn {
		width: 80%;
		margin: 0upx auto;
	}
</style>



